﻿using System;
using System.Collections.Generic;
using br.com.SistemaChamados.DAO;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model;

namespace br.com.SistemaChamados.Controller
{
    public class StateController
    {
        /// <summary>
        /// Método responsável por mandar à camada de persistência um objeto a ser inserido
        /// </summary>
        /// <param name="state">objeto State a ser inserido</param>
        /// <returns>GENERIC_STATE_SUCCESS,GENERIC_STATE_FAILED</returns>
        public EnumGenericState InsertState(State state)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = StateDAO.InsertState(state);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método responsável por mandar um objeto State que necessita ser atualizado à camada de persistência
        /// </summary>
        /// <param name="state">objeto State com os dados atualizados</param>
        /// <returns>GENERIC_STATE_SUCCESS,GENERIC_STATE_FAILED</returns>
        public EnumGenericState UpdateState(State state)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = StateDAO.UpdateState(state);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método responsável por mandar um objeto State à camada de persistência que deve ser removido
        /// </summary>
        /// <param name="state">objeto State a ser removido</param>
        /// <returns>GENERIC_STATE_SUCCESS,GENERIC_STATE_FAILED</returns>
        public EnumGenericState DeleteState(State state)
        {
            EnumGenericState stateTransaction = EnumGenericState.GENERIC_STATE_UNKNOW;
            try
            {
                stateTransaction = StateDAO.DeleteState(state);
            }
            catch (Exception ex)
            {
                stateTransaction = EnumGenericState.GENERIC_STATE_FAILED;
                throw ex;
            }
            return stateTransaction;
        }

        /// <summary>
        /// Método responsável por solicitar à camada de persistência um objeto State de acordo com seu identificador
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public State GetState(int stateId)
        {
            State ValidateStateSelected = new State();
            try
            {
                ValidateStateSelected = StateDAO.getState(stateId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ValidateStateSelected;
        }

        /// <summary>
        /// Método responsável por solicitar à camada de persistência uma lista com objetos State
        /// </summary>
        /// <returns>List<'State'></returns>
        public List<State> GetStates()
        {
            List<State> Returnedlist = new List<State>();
            try
            {
                Returnedlist = StateDAO.getStates();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Returnedlist;
        }

    }
}